package com.pachong.android.baseuicomponent;

import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;

import com.pachong.android.baseuicomponent.adapter.RecyclerViewBaseAdapter;


/**
 * 最后一个item要在水平方向占满屏幕
 * 
 * @author Vivi Peng
 * @date 2015-06-25
 * 
 */
public class LastItemMatchParentSpanSizeLookup extends SpanSizeLookup {

	private RecyclerViewBaseAdapter mAdapter;

	private int mSpanCount = 2;

	public LastItemMatchParentSpanSizeLookup(int spanCount) {
		mSpanCount = spanCount;
	}


	@Override
	public int getSpanSize(int posi) {
		if (mAdapter != null && mAdapter.getItemCount() > 0) {
			int itemCount = mAdapter.getItemCount();
			if(posi == 0 && mAdapter.hasHeaderView()) {
				return mSpanCount;
			}

			if(posi == itemCount - 1 && mAdapter.hasLoadingLayout()) {
				return mSpanCount;
			}
		}
		return 1;
	}


	public void setAdapter(RecyclerViewBaseAdapter adapter) {
		mAdapter = adapter;
	}

}
